package com.wangsanfei.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jfinal.handler.Handler;
import com.jfinal.kit.PropKit;

public class PermissionHandler extends Handler {

	@Override
	public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
		int indexJsp = target.lastIndexOf(".jsp");
		int indexHtml = target.lastIndexOf(".html");
		
		String no_auth_path=PropKit.get("no_auth_path");
		String[] no_auth_paths=no_auth_path.split(",");
		
		boolean flag=true;
		for (String string : no_auth_paths) {
			if(target.indexOf(string)>-1){
				flag=false;
				break;
			}
		}
		
		if(flag){
			if (indexJsp != -1 || indexHtml != -1) {
				if (request.getSession().getAttribute(ConstConfig.SESSION_USER) == null) {
					request.setAttribute("forword", target);
					target = "/wechat/login";
				}
			}
		}
		
		next.handle(target, request, response, isHandled);
	}
}
